package com.prs.crm.action.cdxh;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.prs.crm.domain.cdxh.HrPerson;
import com.prs.crm.domain.cdxh.material.MaterialTeam;
import com.prs.crm.domain.cdxh.molding.Molding;
import com.prs.crm.domain.cdxh.molding.MoldingTeam;
import com.prs.crm.domain.cdxh.production.ProvideRegime;
import com.prs.crm.service.cdxh.HrPersonService;
import com.prs.crm.service.cdxh.MaterialTeamService;
import com.prs.crm.service.cdxh.MoldingService;
import com.prs.crm.service.cdxh.MoldingTeamService;
import com.prs.crm.service.cdxh.ProvideRegimeService;

/**
 * @author LanXiaoGang
 * @E-mail:lan9liang@163.com
 * @qq:7857553326
 * @version 创建时间：2010-12-7 上午10:29:39 简单说明 成型单
 */

public class MoldingAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	private PaginationSupport pagination;

	private Molding molding;

	private MoldingService moldingService;

	private Integer[] ids;
	private  String idss;
	private List<Molding> mdlist = new ArrayList<Molding>();

	private String presentTime = "2010年10月10日";

	private ProvideRegime provideRegime;

	private ProvideRegimeService provideRegimeService;

	private HrPerson hrPerson;

	private MoldingTeam moldingTeam;

	private MoldingTeamService moldingTeamService;

	private HrPersonService hrPersonService;

	private MaterialTeam materialTeam;

	private MaterialTeamService materialTeamService;

	public String receiveNum;

	private String rowdata;
	/**
	 * ajax value
	 * 
	 * @return
	 */
	private String productCode;

	private String orderplan;

	private String needNum;

	private Double backTodNum;
	
    private String allids="";
	
	private String pagetrunNum="";

	@Action("listMoldingTeam")
	public String listMoldingTeam() {
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				Molding.class);
		criteria.add(Restrictions.lt("showState", 6));
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getMoldingService().listByPage(criteria,
				pagination));
		return SUCCESS;
	}

	@Action("listMoldingMoldingTeam")
	public String listMoldingMoldingTeam() {
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				MoldingTeam.class);
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getMaterialTeamService().listByPage(criteria,
				pagination));
		return SUCCESS;
	}

	@Action("editMoldingTeam")
	public String editMoldingTeam() {
		String[] ss=pagetrunNum.split(",");
		for(int j=0;j<ss.length;j++){
			if(ss[j]!=""){	
		
			Molding mdObject = this.getMoldingService().get(Integer.parseInt(ss[j]));
			mdlist.add(mdObject);
			if(idss==null){
				idss=ss[j];
			}else{
				idss=idss+","+ss[j];
			}
		}
		}
		presentTime = getPresentTimes();
		return SUCCESS;
	}

	@Action("viewMoldingTeam")
	public String viewMoldingTeam(){
		moldingTeam=this.getMoldingTeamService().get(moldingTeam.getId());
		
		return SUCCESS;
	}
	
	@Action("YSPrintClass")
	public String YSPrintClass() {
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				ProvideRegime.class);
		criteria.add(Restrictions.eq("productStyle", "印刷"));
		criteria.add(Restrictions.eq("inserValue", "1"));
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getProvideRegimeService().listByPage(criteria,
				pagination));
		return SUCCESS;
	}

	@Action("YSProductPerson")
	public String YSProductPerson() {
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				HrPerson.class);
		criteria.add(Restrictions.eq("hrDepartment", "印刷组"));
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getHrPersonService().listByPage(criteria,
				pagination));
		return SUCCESS;
	}

	@Action("CXMoldingClass")
	public String pLMachineClass() {
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				ProvideRegime.class);
		criteria.add(Restrictions.eq("productStyle", "成型"));
		criteria.add(Restrictions.eq("inserValue", "1"));
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getProvideRegimeService().listByPage(criteria,
				pagination));
		return SUCCESS;
	}

	@Action("CXProductPerson")
	public String pLProductPerson() {
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				HrPerson.class);
		criteria.add(Restrictions.eq("hrDepartment", "成型组"));
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getHrPersonService().listByPage(criteria,
				pagination));
		return SUCCESS;
	}

	@Action(value = "getReceiveMaterial", results = { @Result(name = "success", type = "json", params = {
			"root", "rowdata" }) })
	public String getReceiveMaterial() {
		MaterialTeam mtObject = this.getMaterialTeamService().getMaterialTeam(
				productCode, orderplan);
//		System.out.println("得到的ID值" + mtObject.getId());
//		System.out.println("查询到的数据=" + mtObject.getMaterialSyWuLiao());
		this.rowdata = mtObject.getMaterialSyWuLiao();
		return SUCCESS;
	}

	/**
	 * 打回到配料组那里重新制定
	 * 
	 * @return
	 */
	@Action(value = "backTrackMaterialTeam", results = { @Result(name = "success", type = "json", params = {
			"root", "rowdata" }) })
	public String backTrackMaterialTeam() {
		this.getMaterialTeamService().returnTrackMaterialTeam(productCode,
				orderplan, needNum);
		this.rowdata = "A";
		return SUCCESS;
	}

	/**
	 * 把还料加到对应的配料那里去
	 * 
	 * @return
	 */
	@Action(value = "backToMaterialTeam", results = { @Result(name = "success", type = "json", params = {
			"root", "rowdata" }) })
	public String backToMaterialTeam() {
		this.rowdata = "B";
		return SUCCESS;
	}

	
	
	
	public PaginationSupport getPagination() {
		return pagination;
	}

	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}

	public Molding getMolding() {
		return molding;
	}

	public void setMolding(Molding molding) {
		this.molding = molding;
	}

	public MoldingService getMoldingService() {
		return moldingService;
	}

	public void setMoldingService(MoldingService moldingService) {
		this.moldingService = moldingService;
	}

	public Integer[] getIds() {
		return ids;
	}

	public void setIds(Integer[] ids) {
		this.ids = ids;
	}

	String getPresentTimes() {
		int yyyy, MM, dd;
		Calendar c = Calendar.getInstance();
		yyyy = c.get(Calendar.YEAR);
		MM = c.get(Calendar.MONTH) + 1;
		dd = c.get(Calendar.DAY_OF_MONTH);
		String Times = yyyy + "年" + MM + "月" + dd + "日";
		return Times;
	}

	public String getPresentTime() {
		return presentTime;
	}

	public void setPresentTime(String presentTime) {
		this.presentTime = presentTime;
	}

	public List<Molding> getMdlist() {
		return mdlist;
	}

	public void setMdlist(List<Molding> mdlist) {
		this.mdlist = mdlist;
	}

	public ProvideRegime getProvideRegime() {
		return provideRegime;
	}

	public void setProvideRegime(ProvideRegime provideRegime) {
		this.provideRegime = provideRegime;
	}

	public ProvideRegimeService getProvideRegimeService() {
		return provideRegimeService;
	}

	public void setProvideRegimeService(
			ProvideRegimeService provideRegimeService) {
		this.provideRegimeService = provideRegimeService;
	}

	public HrPerson getHrPerson() {
		return hrPerson;
	}

	public void setHrPerson(HrPerson hrPerson) {
		this.hrPerson = hrPerson;
	}

	public HrPersonService getHrPersonService() {
		return hrPersonService;
	}

	public void setHrPersonService(HrPersonService hrPersonService) {
		this.hrPersonService = hrPersonService;
	}

	public String getReceiveNum() {
		return receiveNum;
	}

	public void setReceiveNum(String receiveNum) {
		this.receiveNum = receiveNum;
	}

	public String getProductCode() {
		return productCode;
	}

	public void setProductCode(String productCode) {
		this.productCode = productCode;
	}

	public String getOrderplan() {
		return orderplan;
	}

	public void setOrderplan(String orderplan) {
		this.orderplan = orderplan;
	}

	public MaterialTeam getMaterialTeam() {
		return materialTeam;
	}

	public void setMaterialTeam(MaterialTeam materialTeam) {
		this.materialTeam = materialTeam;
	}

	public MaterialTeamService getMaterialTeamService() {
		return materialTeamService;
	}

	public void setMaterialTeamService(MaterialTeamService materialTeamService) {
		this.materialTeamService = materialTeamService;
	}

	public String getRowdata() {
		return rowdata;
	}

	public void setRowdata(String rowdata) {
		this.rowdata = rowdata;
	}

	public String getNeedNum() {
		return needNum;
	}

	public void setNeedNum(String needNum) {
		this.needNum = needNum;
	}

	public Double getBackTodNum() {
		return backTodNum;
	}

	public void setBackTodNum(Double backTodNum) {
		this.backTodNum = backTodNum;
	}

	public MoldingTeam getMoldingTeam() {
		return moldingTeam;
	}

	public void setMoldingTeam(MoldingTeam moldingTeam) {
		this.moldingTeam = moldingTeam;
	}

	public MoldingTeamService getMoldingTeamService() {
		return moldingTeamService;
	}

	public void setMoldingTeamService(MoldingTeamService moldingTeamService) {
		this.moldingTeamService = moldingTeamService;
	}

	public String getIdss() {
		return idss;
	}

	public void setIdss(String idss) {
		this.idss = idss;
	}

	public String getAllids() {
		return allids;
	}

	public void setAllids(String allids) {
		this.allids = allids;
	}

	public String getPagetrunNum() {
		return pagetrunNum;
	}

	public void setPagetrunNum(String pagetrunNum) {
		this.pagetrunNum = pagetrunNum;
	}

}
